import Animator from "@ohos.animator";
import prompt from '@system.prompt';
export default {
    data: {
        requestId: 0,
        startTime: 0,
        divWidth: 200,
        divHeight: 200,
        animator: null
    },
    onInit() {
        var options = {
            duration: 1500,
            easing: 'friction',
            fill: 'forwards',
            iterations: 2,
            begin: 200.0,
            end: 400.0
        };
        this.animator = Animator.createAnimator(options);
    },
    beginAnimation() {
      cancelAnimationFrame(this.requestId);
      this.requestId = requestAnimationFrame(this.runAnimation);
    },
    runAnimation(timestamp) {
      if (this.startTime == 0) {
          this.startTime = timestamp;
      }
      var elapsed = timestamp - this.startTime;
      if (elapsed < 500) {
        console.log('callback handler timestamp: ' + timestamp);
        this.requestId = requestAnimationFrame(this.runAnimation);
      }
    },
    stopAnimation() {
      cancelAnimationFrame(this.requestId);
    },
    Show() {
        var options1 = {
            duration: 5000,
            easing: 'friction',
            fill: 'forwards',
            iterations: 1,
            begin: 200.0,
            end: 400.0
        };
        this.animator.update(options1);
        this.animator.onframe = (value) =>{
            console.log(value)
            this.divWidth = value;
            this.divHeight = value;
        };
        this.animator.play();
    },
}
